#ifndef FUZZYTABLEMODEL_H_
#define FUZZYTABLEMODEL_H_

#include <QtGui>

// ======================================================================
class FuzzyTableModel : public QAbstractTableModel {
private:
    int                          m_nRows;
    int                          m_nColumns;
    QHash<QModelIndex, QVariant> m_hash;

public:
    FuzzyTableModel(int nRows, int nColumns, QObject* pobj = 0)
        : QAbstractTableModel(pobj)
        , m_nRows(nRows)
        , m_nColumns(nColumns) 
    { 
    }
   /*
    void createTable (int nRows, int nColumns)
    {
    	m_nRows = nRows;
    	m_nColumns = nColumns;
    	
    }
    */
    QVariant data(const QModelIndex& index, int nRole) const
    {
        if (!index.isValid())
        {
            return QVariant();
        }
        
        //QString str = QString("%1,%2").arg(index.row() + 1).arg(index.column() + 1);
        return (nRole == Qt::DisplayRole || nRole == Qt::EditRole) 
               ? m_hash.value(index, QVariant()) 
               : QVariant();
    }
    
    bool setData(const QModelIndex& index, 
                 const QVariant&    value, 
                 int                nRole
                )
    {
        if (index.isValid() && nRole == Qt::EditRole) 
        {
            m_hash[index] = value;
            emit dataChanged(index, index);
            return true;
        }
        return false;
    }

    int rowCount(const QModelIndex&) const 
    { 
        return m_nRows; 
    }

    int columnCount(const QModelIndex&) const 
    { 
        return m_nColumns; 
    }

    Qt::ItemFlags flags(const QModelIndex& index) const
    {
        Qt::ItemFlags flags = QAbstractTableModel::flags(index);
        return index.isValid() ? (flags | Qt::ItemIsEditable)
                               : flags;
    }
};

#endif /*FUZZYTABLEMODEL_H_*/
